package com.sczmgk.hotline.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.CheckBox;
import android.widget.RadioButton;

import com.sczmgk.hotline.R;

/**
 * Created by bo on 2016/4/28.
 */
public class CheckboxUtils {
    public static void setCheckBoxImage(CheckBox checkBox, Context context){
        float screenDensity = CommonUtils.getScreenDensity(context);
        float r1 = 15*screenDensity;
        float b1 = 15*screenDensity;
        int r = (int)r1;
        int b = (int)b1;
        Drawable myImage = context.getResources().getDrawable(R.drawable.check_box_selector);//将资源转成Drawable
        myImage.setBounds(0, 0, r, b);//设置图片的大小
        checkBox.setCompoundDrawables(myImage, null, null, null);//设置图片在左边显示
        checkBox.setGravity(Gravity.CENTER);
    }
    public static void setRadioButtonImage(RadioButton radioButton, Context context, int ImageResourceId){
        float screenDensity = CommonUtils.getScreenDensity(context);
        float r1 = 35*screenDensity;
        float b1 = 35*screenDensity;
        int r = (int)r1;
        int b = (int)b1;
        Drawable myImage = context.getResources().getDrawable(ImageResourceId);//将资源转成Drawable
        myImage.setBounds(0, 0, r, b);//设置图片的大小
        radioButton.setCompoundDrawables(null, myImage, null, null);//设置图片在上面边显示
        radioButton.setGravity(Gravity.CENTER);
    }

    public static void setRadioButtonImageBg(RadioButton radioButton, Context context, int ImageResourceId){
        float screenDensity = CommonUtils.getScreenDensity(context);
        float r1 = 35*screenDensity;
        float b1 = 35*screenDensity;
        int r = (int)r1;
        int b = (int)b1;
        Drawable myImage = context.getResources().getDrawable(ImageResourceId);//将资源转成Drawable
        myImage.setBounds(0, 0, r, b);//设置图片的大小
        radioButton.setCompoundDrawables(null, myImage, null, null);//设置图片在上面边显示
        radioButton.setGravity(Gravity.CENTER);
    }

}
